var e = require("bmob.js");

module.exports.getUserInfo = function() {
    var o = new e.User(), n = this;
    wx.login({
        success: function(s) {
            console.log(s), o.loginWithWeapp(s.code).then(function(o) {
                var t = o.get("authData").weapp.openid;
                if (wx.setStorageSync("openid", t), console.log(o, "user", o.id, s), o.get("nickName")) console.log(o.get("nickName"), 'res.get("nickName")'), 
                getApp().globalData.userInfo = o; else {
                    var c = e.Object.extend("_User");
                    new e.Query(c).get(o.id, {
                        success: function(e) {
                            wx.setStorageSync("own", e.get("uid"));
                        },
                        error: function(e, o) {
                            console.log("查询失败");
                        }
                    }), wx.getUserInfo({
                        success: function(s) {
                            var c = s.userInfo;
                            getApp().globalData.userInfo = c, console.log(" 全局变量  " + n.globalData.userInfo);
                            var r = c.nickName, a = c.avatarUrl, i = e.Object.extend("_User");
                            new e.Query(i).get(o.id, {
                                success: function(e) {
                                    e.set("nickName", r), e.set("userPic", a), e.set("openid", t), e.save();
                                }
                            });
                        }
                    });
                }
            }, function(e) {
                console.log(e, "errr");
            });
        }
    });
};